package version1_2_2;

import version1_1.*;
import version1_2_1.People;

/**
 * @program:IntelliJ IDEA
 * @Description:使用第二种线程创建的方法
 * @author:Mr.CheCheHuiBujianO
 * @data: 2022/7/13 11:15
 */
public class GameThread2 implements Runnable{
    /**
     * When an object implementing interface <code>Runnable</code> is used
     * to create a thread, starting the thread causes the object's
     * <code>run</code> method to be called in that separately executing
     * thread.
     * <p>
     * The general contract of the method <code>run</code> is that it may
     * take any action whatsoever.
     *
     * @see Thread#run()
     */
    @Override
    public void run() {
        //使用继承Thread类进行
        int gameTime = 0;//游戏进行局数
        int gameWinTime = 0;//游戏胜利局数
        int gameLoseTime = 0;//游戏失败局数

        //使用多态的写法进行对象的创建
        User person = new People();
        person.setName();//设置名字
        person.getId();//设置id

        User computer = new Computer();
        computer.setName();
        computer.getId();

        GestureTransition gestureTransition = new GestureTransitionIMPH();
        GameJudge gameJudge = new GameJudgeIMPH();

        //游戏环节
        while(gameTime < 5 && gameWinTime < 3 && gameLoseTime < 3){
            person.setGesture();//人的手势
            computer.setGesture();//电脑手势
            //将手势转化为int类型
            int personGesture = gestureTransition.gesture(person.getGesture());
            int computerGesture = gestureTransition.gesture(computer.getGesture());
            //将转化后的手势扔进判断函数进行判断
            String gameResult = gameJudge.gameJudge(personGesture, computerGesture);
            switch (gameResult){
                case "胜利":
                    gameWinTime++;
                    gameTime++;
                    new GameJudgeIMPH().printResult(gameWinTime,gameLoseTime,gameTime,gameResult);
                    break;
                case "失败":
                    gameLoseTime++;
                    gameTime++;
                    new GameJudgeIMPH().printResult(gameWinTime,gameLoseTime,gameTime,gameResult);
                    break;
                case "平局":
                    gameTime++;
                    new GameJudgeIMPH().printResult(gameWinTime,gameLoseTime,gameTime,gameResult);
                    break;
                default:
                    System.out.println("请检查你的输入！！！");
            }
        }
    }
}
